<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>继承</title>
  </head>
  <body>
    <script>
      // 使用 extends 和 super 关键字
      class Father {
        constructor(x, y) {
          this.x = x;
          this.y = y;
        }

        sum() {
          console.log(this.x + this.y);
        }
      }

      // 继承
      class Son extends Father {
        constructor(x, y) {
          super(x, y); // 调用父类中的构造函数
        }
      }

      var son = new Son(1, 2);
      son.sum();
    </script>
  </body>
</html>
